package {{apiPackage}};

import static org.springframework.http.MediaType.*;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
{{#imports}}import {{import}};
{{/imports}}
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.springframework.util.MultiValueMap;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

{{#operations}}
public class {{classname}} {
{{#operation}}

  public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>consumer/queryParamsConsumer}}{{>consumer/pathParamsConsumer}}{{>consumer/headerParamsConsumer}}{{>consumer/bodyParamsConsumer}}{{>consumer/formParamsConsumer}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {

    Map<String, Object> params = new HashMap<>();
    HttpEntity httpEntity = null;
    HttpHeaders headers = new HttpHeaders();
    {{#allParams}}
    {{#isPathParam}}
    params.put("{{paramName}}",{{paramName}});
    {{/isPathParam}}
    {{#isQueryParam}}
    params.put("{{paramName}}",{{paramName}});
    {{/isQueryParam}}
    {{#isHeaderParam}}
    headers.add("{{paramName}}",{{paramName}});
    {{/isHeaderParam}}
    {{#isFormParam}}
    {{^isFile}}
    httpEntity =  new HttpEntity<{{{dataType}}}>({{paramName}}, headers);
    {{/isFile}}
    {{#isFile}}
    httpEntity =  new HttpEntity<MultipartFile>({{paramName}}, headers);
    {{/isFile}}
    {{/isFormParam}}
    {{#isBodyParam}}
    httpEntity =  new HttpEntity<{{{dataType}}}>({{paramName}}, headers);
    {{/isBodyParam}}
    {{/allParams}}

    RestTemplate restTemplate = RestTemplateBuilder.create();

    ResponseEntity<{{>returnTypes}}> result = restTemplate.exchange("cse://{{providerServiceId}}{{#getRelativeBasePath}}{{basePath}}{{/getRelativeBasePath}}{{path}}",HttpMethod.{{httpMethod}},httpEntity,{{#getGenericClassType}}{{>returnTypes}}{{/getGenericClassType}}.class,params);

    // do something

    return result;
  }
{{/operation}}
}
{{/operations}}